#include "linux/interrupt.h"
#include "linux/init.h"
#include "linux/interrupt.h"
#include "linux/of_irq.h"
#include "linux/printk.h"
#include "linux/platform_device.h"

irqreturn_t imx6ull_key_irq_handler(int irq, void *arg)
{
    printk("key irq handler\n");
    return IRQ_HANDLED;
}

int keyio_init(void)
{
    int ret;
    int irq;
    struct device_node *nd;

    nd = of_find_node_by_path("/key");
    if (!nd)
    {
        printk("key node not found!\n");
        return -ENODEV;
    }

    irq = irq_of_parse_and_map(nd, 0);
    if (irq < 0)
    {
        printk("key: failed to get irq\n");
        return irq;
    }

    printk("key: got irq %d\n", irq);

    ret = request_irq(irq, imx6ull_key_irq_handler, IRQF_TRIGGER_FALLING, "key", NULL);
    if (ret)
    {
        printk("key: request irq %d failed, ret=%d\n", irq, ret);
        return ret;
    }

    return ret < 0 ? ret : 0;
}

int imx6ull_key_init(void)
{
    int ret;
    ret = keyio_init();
    if (ret)
    {

    }

    //register_chrdev_region();

    return ret;
}

void imx6ull_key_exit(void)
{

}

module_init(imx6ull_key_init);
module_exit(imx6ull_key_exit);